import {Issue, rewriteIssuesJson} from '../src/rewriteIssuesJson'
import {expect} from 'chai'
import {readFile} from '../src/utils'
import fs from 'fs'

describe('rewriteIssuesJson', () => {
    it('should rewrite issues json', async () => {
        const originalIssuesPath = 'test/issues_origin.json'
        const outputIssuesPath = 'test/issues.json'
        await rewriteIssuesJson(originalIssuesPath, outputIssuesPath)
        const issues = await readFile(outputIssuesPath)
        const parsedIssues:Issue = JSON.parse(issues)[0]
        expect(parsedIssues.beginColumn).to.equal(12)
        expect(parsedIssues.endColumn).to.equal(498)
        expect(parsedIssues.beginLine).to.equal(27)
        expect(parsedIssues.endLine).to.equal(27)
        expect(parsedIssues.location).to.equal('cmd/chat/main.go')
        expect(parsedIssues.description).to.equal('Error return value of `router.Run` is not checked')
        expect(parsedIssues.ruleName).to.equal('errcheck')
        expect(parsedIssues.title).to.equal('errcheck')
        expect(parsedIssues.level).to.equal('BLOCKER')
        fs.unlinkSync(outputIssuesPath)
    })
})